package cn.itcast.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author :HCH
 * @version : 1.0.0
 * @date :Created in 2019/7/10 19:54
 * @description :TODO
 * @modified :
 */

@Slf4j
public class DataConverter implements Converter<String, Date> {

    private String datePattern;

    public void setDatePattern(String datePattern) {
        this.datePattern = datePattern;
    }


    @Override
    public Date convert(String s) {
        SimpleDateFormat dateFormat = new SimpleDateFormat(this.datePattern);
        try {
            return dateFormat.parse(s);
        }catch (ParseException e){
            log.error("convertError",e);
        }
        return null;
    }
}
